package com.matt.repository.record;

import com.matt.domain.ChildrenNurseryInfoRecord;
import com.matt.domain.courseV2.VendorCourse;
import com.matt.domain.photoalbum.Photo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/21
 * *******************************
 */
public interface ChildrenNurseryInfoRecordRepository extends JpaRepository<ChildrenNurseryInfoRecord, String> , JpaSpecificationExecutor<ChildrenNurseryInfoRecord> {

    Page<ChildrenNurseryInfoRecord> findAllByAndChildrenId(String childrenId, Pageable pageRequest);

    @Query(value="SELECT * FROM children_nursery_info_record WHERE  childrenId = ?1 and  DATE_FORMAT(beginDate,'%Y-%m-%d')   >= DATE_FORMAT(?2,'%Y-%m-%d')" +
            " and  DATE_FORMAT(endDate,'%Y-%m-%d')    >= DATE_FORMAT(?3,'%Y-%m-%d') ",nativeQuery = true)
    List<ChildrenNurseryInfoRecord> findAllByAndChildrenIdTime(String childrenId, Date beginDate,Date endDate);

    @Query(value="SELECT * FROM children_nursery_info_record WHERE  childrenId = ?1 and  DATE_FORMAT(beginDate,'%Y-%m-%d')   >= DATE_FORMAT(?2,'%Y-%m-%d')" +
            " and  DATE_FORMAT(endDate,'%Y-%m-%d')    >= DATE_FORMAT(?3,'%Y-%m-%d') and status = ?4",nativeQuery = true)
    ChildrenNurseryInfoRecord findByChildrenIdAndBeginDateAndStatus(String childrenId, Date beginDate,Date endDate,Integer status);

    List<ChildrenNurseryInfoRecord> findByChildrenIdIn(String[] childrenIds);
}
